package com.ydd.controller.admin;

import com.ydd.dto.YddAdvAddDTO;
import com.ydd.dto.YddAdvDTO;
import com.ydd.dto.YddAdvposQueryDTO;
import com.ydd.entity.YddAdvpos;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.AdvposService;
import com.ydd.vo.DataListVO;
import com.ydd.vo.YddAdvposAllVO;
import com.ydd.vo.YddAdvposQueryVO;
import com.ydd.vo.YddAdvposRowInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ydd_advpos")
@Slf4j
@Api(tags = "广告管理")
public class AdvposController {
    @Autowired
    private AdvposService advposService;

    /**
     * 广告位动态分页查询
     * @param yddAdvposQueryDTO
     * @return
     */
    @ApiOperation("广告位动态分页查询")
    @GetMapping("/list")
    public Result findByAdvpos(YddAdvposQueryDTO yddAdvposQueryDTO){
        DataListVO dataListVO=advposService.findByAdvpos(yddAdvposQueryDTO);
        return Result.success(dataListVO);
    }

    /**
     * 修改广告位
     * @param yddAdvDTO
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("广告位修改")
    public Result updateAdvpos(@RequestBody YddAdvDTO yddAdvDTO){
        advposService.updateAdvpos(yddAdvDTO);
        return Result.success();
    }

    /**
     * get广告位详情
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    public Result rowInfoAdvpos(String id){
        YddAdvposRowInfoVO yddAdvposRowInfoVO=advposService.rowInfoAdvpos(id);
        return Result.success(yddAdvposRowInfoVO);
    }

    /**
     * 根据ID删除数据
     * @param id
     * @return
     */
    @GetMapping("/del")
    public Result delAdvpos(String id){
        advposService.delAdvpos(id);
        return Result.success();
    }

    /**
     * 查询所有广告位
     * @return
     */
    @GetMapping("/all")
    public Result selectAll(){
        YddAdvposAllVO yddAdvposAllVO = advposService.selectAll();
        return Result.success(yddAdvposAllVO);
    }

    /**
     * 新增广告位
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加广告位")
    public Result addAdvpos(@RequestBody YddAdvpos yddAdvpos){
        advposService.addAdvpos(yddAdvpos);
        return Result.success();
    }
}
